//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using CommunityServer.Components;
using CommunityServer.Configuration;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Controls
{
	/// <summary>
	/// Summary description for NntpInformation.
	/// </summary>
	public class NntpInformation : TemplatedWebControl
	{
		IText content;
		CSContext csContext = CSContext.Current;
			
		protected override void AttachChildControls() 
		{
			content = FindText("Content");
		}

		protected override void OnLoad(EventArgs e) 
		{
			if (!Telligent.Registration.NntpServer.IsLicenseAvailable || Globals.IsNullorEmpty(csContext.SiteSettings.NntpServerLocation))
				throw new CSException(CSExceptionType.AccessDenied, "No NNTP server license is installed or the NNTP server location is undefined.");

			if (csContext.User.IsAnonymous)
			{
				this.Visible = false;
				return;
			}

			Head.AddSiteNameTitle(ResourceManager.GetString("NntpInformation_Title"), Context);
			UsersOnline.SetLocation(ResourceManager.GetString("NntpInformation_Title"));

			this.DataBind();
			base.OnLoad (e);
		}

		public override void DataBind() 
		{
			base.DataBind();

			if (content != null)
				content.Text = string.Format(ResourceManager.GetString("NntpInformation_Content"), csContext.SiteSettings.NntpServerLocation, Globals.ApplicationPath);
		}
	}
}
